<?php

/**
 * 发包记录
 * @author jc
 */
namespace app\common\model;

use think\Db;
use think\Model;

class CoreOrderDelivery extends Model
{
    protected $name = 'core_order_delivery';
    // 追加属性
    protected $append = [
        'status_text',
        'express_code',
        'express_name',
    ];

    const TYPE_1 = 1;
    const TYPE_2 = 2;

    const STATUS_0 = 0;
    const STATUS_1 = 1;
    const STATUS_2 = 2;
    const STATUS_3 = 3;

    public static function statusMap()
    {
        return [
            self::STATUS_0 => '待收货',
            self::STATUS_1 => '已收货',
            self::STATUS_2 => '已核销',
            self::STATUS_3 => '部分收货',
        ];
    }

    public static function typeMap()
    {
        return [
            self::TYPE_1 => '快递',
            self::TYPE_2 => '自提',
        ];
    }

    /**
     * 获取状态映射
     * @return  array   状态映射表
     */
    public function getStatusMap()
    {
        return [
            self::STATUS_0  => '运输中',
            self::STATUS_1  => '已签收',
        ];
    }


    public static function expressMap()
    {
        return [
            1 => ['id' => 1, 'name' => '中通快递', 'code' => 'zhongtong'],
            2 => ['id' => 2, 'name' => '圆通速递', 'code' => 'yuantong'],
            3 => ['id' => 3, 'name' => '申通快递', 'code' => 'shentong'],
            4 => ['id' => 4, 'name' => '百世快运', 'code' => 'bsky'],
            5 => ['id' => 5, 'name' => '顺丰速运', 'code' => 'shunfeng'],
            6 => ['id' => 6, 'name' => '韵达快运', 'code' => 'yunda'],
            7 => ['id' => 7, 'name' => '百世快递', 'code' => 'huitong'],
            8 => ['id' => 8, 'name' => '天天快递', 'code' => 'tiantian'],
        ];
    }
    
    public function getStatusTextAttr($value, $data)
    {
        $map = $this->getStatusMap();
        return $map[$data['status']] ?? '';
    }


    public function getExpressCodeAttr($value, $data)
    {
        $map = $this->expressMap();
        return $map[$data['express_id']]['code'] ?? '';
    }

    public function getExpressNameAttr($value, $data)
    {
        $map = $this->expressMap();
        return $map[$data['express_id']]['name'] ?? '';
    }

}
